#nullable enable

using System;
using System.Collections.Generic;
using System.ComponentModel;
using Volo.Abp.Domain.Entities;

namespace PHMEE.EnergyEfficiency;

public class VesselEeConfig : Entity<Guid>
{
    public VesselEeConfig(Guid id) : base(id)
    {
    }

    private VesselEeConfig()
    {
    }

    /// <summary>
    /// 船队 Id
    /// 用于能效 1.0 左侧边栏，根据船队 ID 获取船队种各船舶的信息
    /// </summary>
    public Guid FleetId { get; set; }

    /// <summary>
    /// 船名
    /// 用于页面展示
    /// </summary>
    public string Name { get; set; } = null!;

    /// <summary>
    /// IMO 号
    /// 用于页面展示
    /// </summary>
    public int IMO { get; set; }

    /// <summary>
    /// 呼号
    /// 用于页面展示
    /// </summary>
    public string CallSign { get; set; } = null!;

    /// <summary>
    /// 船型
    /// 用于页面展示和业务逻辑计算
    /// </summary>
    public VesselType VesselType { get; set; }

    /// <summary>
    /// 净吨
    /// 用于页面展示和业务逻辑计算
    /// </summary>
    public float NT { get; set; }

    /// <summary>
    /// 总吨
    /// 用于页面展示和业务逻辑计算
    /// </summary>
    public float GT { get; set; }

    /// <summary>
    /// 设计载重吨
    /// 用于页面展示和业务逻辑计算
    /// </summary>
    public float DWT { get; set; }

    /// <summary>
    /// 船旗国
    /// 用于页面展示
    /// </summary>
    public string FlagState { get; set; } = null!;

    /// <summary>
    /// 船级社
    /// 用于页面展示
    /// </summary>
    public string ClassificationSociety { get; set; } = null!;

    /// <summary>
    /// 船用油品类型（使用 JSON 类型保存在一个字段中）
    /// 用于页面展示和业务逻辑计算
    /// </summary>
    public List<FuelType> FuelTypes { get; set; } = [];

    /// <summary>
    /// EEDI
    /// 用于页面展示
    /// </summary>
    public float EEDI { get; set; }

    /// <summary>
    /// EEXI
    /// 用于页面展示
    /// </summary>
    public float EEXI { get; set; }

    /// <summary>
    /// 冰级
    /// 用于页面展示和业务逻辑计算
    /// </summary>
    public IceClass IceClass { get; set; }

    #region Power Output

    // 这部分只用于报表导出，都是富文本框字符串，用户输入什么，导出报表时就导出什么

    public string MainPropulsionPowerOutput { get; set; } = null!;

    public string AuxiliaryEnginesPowerOutput { get; set; } = null!;

    #endregion

    /// <summary>
    /// 船管理公司
    /// 用于页面展示
    /// </summary>
    public string ManagementCompany { get; set; } = null!;

    /// <summary>
    /// CII 数值单位表达形式
    /// 计算值，不存储，不需要在 MySQL 中建列，与船舶类型强关联
    /// </summary>
    public ApplicableCII? ApplicableCII => ApplicableCIIHelper.GetByVesselType(VesselType);

    /// <summary>
    /// STS 航次或穿梭油船的修正系数
    /// 用于业务逻辑计算
    /// </summary>
    public float FtTanker { get; set; }

    /// <summary>
    /// 冰级船舶载运能力修正系数
    /// 用于业务逻辑计算
    /// </summary>
    public float Fi { get; set; }

    /// <summary>
    /// 冰级船舶的修正系数
    /// 用于业务逻辑计算
    /// </summary>
    public float Fm { get; set; }

    /// <summary>
    /// 化学品船舱容修正系数
    /// 用于业务逻辑计算
    /// </summary>
    public float Fc { get; set; }

    /// <summary>
    /// 船舶特定自愿结构加强修正系数
    /// 用于业务逻辑计算
    /// </summary>
    public float FiVSE { get; set; }

    /// <summary>
    /// 该船的航速和 CII 的映射关系
    /// 用于业务逻辑计算
    /// </summary>
    public List<VToCII> VToCIIs { get; set; } = [];

    /// <summary>
    /// CII 图表默认纵轴边界
    /// 用于前端显示
    /// </summary>
    public CIIDefaultBound CIIDefaultBound { get; set; }

    /// <summary>
    /// LogAbstract 手填锁密码
    /// </summary>
    public string? LogAbstractPass { get; set; }

    /// <summary>
    /// 燃油是否自动采集
    /// </summary>
    public bool IsFuelAutoCollect { get; set; }

    /// <summary>
    /// Gps 是否自动采集
    /// </summary>
    public bool IsGpsAutoCollect { get; set; }
}

public class CIIDefaultBound
{
    public float Min { get; set; }

    public float Max { get; set; }
}

/// <summary>
/// 冰级
/// </summary>
public enum IceClass
{
    [Description("N/A")] NA = 0,

    [Description("IA Super")] IASuper = 1,

    [Description("IA")] IA = 2,

    [Description("IB")] IB = 3,

    [Description("IC")] IC = 4
}

public enum ApplicableCII
{
    [Description("AER")] AER = 0,

    [Description("cgDIST")] CgDIST = 1,
}

public static class ApplicableCIIHelper
{
    /*
     AER或cgDIST
1.以下船型用AER：Bulk carrier,Gas carrier,Tanker,Container ship,General cargo ship,Refrigerated cargo carrier,Combination carrier,LNG carrier
2，以下船型用cgDIST：Ro-ro cargo ship（vehicle carrier），Ro-ro cargo ship,Ro-ro passenger ship,High-speed carft designed to SOLAS chapter X,Cruise passenger ship
     */
    public static ApplicableCII? GetByVesselType(VesselType vesselType)
    {
        return vesselType switch
        {
            VesselType.BulkCarrier => ApplicableCII.AER,
            VesselType.GasCarrier => ApplicableCII.AER,
            VesselType.Tanker => ApplicableCII.AER,
            VesselType.ContainerShip => ApplicableCII.AER,
            VesselType.GeneralCargoShip => ApplicableCII.AER,
            VesselType.RefrigeratedCargoCarrier => ApplicableCII.AER,
            VesselType.CombinationCarrier => ApplicableCII.AER,
            VesselType.LNGCarrier => ApplicableCII.AER,
            VesselType.RoRoCargoShipVehicleCarrier => ApplicableCII.CgDIST,
            VesselType.RoRoCargoShip => ApplicableCII.CgDIST,
            VesselType.RoRoPassengerShip => ApplicableCII.CgDIST,
            VesselType.RoRoPassengerShipHighSpeedCraftDesignedToSOLASChapterX => ApplicableCII.CgDIST,
            VesselType.CruisePassengerShip => ApplicableCII.CgDIST,
            _ => null
        };
    }
}